package test;

import okhttp3.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Carman
 * <p>
 * Date: 2018/4/17 - 11:48
 * <p>
 * 描述:
 */
public class JsonRequest {
    public static final String params = "[\n" +
            "    {\n" +
            "        \"cameraSign\": \"aaaaaaaaaaaaaaaaaa\",\n" +
            "        \"uirSign\": \"HD\",\n" +
            "        \"videoUri\": \"rtsp://\"\n" +
            "    },\n" +
            "    {\n" +
            "        \"cameraSign\": \"aaaaaaaaaaaaaaaaaa\",\n" +
            "        \"uirSign\": \"HD\",\n" +
            "        \"videoUri\": \"rtsp://\"\n" +
            "    }\n" +
            "]";

    public static final String url = "http://10.167.194.220:8080/task";

    public static void main(String[] args) {
        httpUtils();
    }

    public static void httpUtils() {
    }

    static class RecordTask {
        private String cameraSign;
        private String videoUri;
        private String uirSign;

        public RecordTask() {
        }

        public RecordTask(String cameraSign, String videoUri, String uirSign) {
            this.cameraSign = cameraSign;
            this.videoUri = videoUri;
            this.uirSign = uirSign;
        }
    }

    public void test1(){
        List<RecordTask> recordTasks = new ArrayList<>();
        RecordTask task = new RecordTask("aaaaaa", "rtsp://11", "HD");
        RecordTask task1 = new RecordTask("bbbbbb", "rtsp://22", "HD");
        recordTasks.add(task);
        recordTasks.add(task1);
        OkHttpClient client = new OkHttpClient();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody requestBody = RequestBody.create(mediaType, params);
        Request request = new Request.Builder().post(requestBody)//Post请求的参数传递
                .url(url).build();
        try {
            Response response = client.newCall(request).execute();
            String result = response.body().string();
            System.out.println("response: " + result);
            response.body().close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



}
